import { LOGIN_SUCCESS } from "../actions";



if ((window.location.href.indexOf('openid') < 0 || !window.location.href.split('=')[1]) && !localStorage.getItem("userInfo")) {
  window.location.href = 'http://www.yermn.com/api/auth/login?url=http://www.yermn.com/#/me'
}

export let initState = {
  userInfo: JSON.parse(localStorage.getItem("userInfo"))
};

export default function (state = initState, action) {
  switch (action.type) {
  case LOGIN_SUCCESS:
    action.data &&
      localStorage.setItem("userInfo", JSON.stringify(action.data));
    return { ...state, userInfo: { ...action.data } };
  default:
    return {
      ...state
    };
  }
}